package com.ruoyi.project.gxgw_modules.pet.service;

import java.util.List;

import com.ruoyi.project.gxgw_modules.common.CheckState;
import com.ruoyi.project.gxgw_modules.pet.constant.PetAuthState;
import com.ruoyi.project.gxgw_modules.pet.domain.Pet;
import com.ruoyi.project.gxgw_modules.pet.mapper.PetMapper;
import com.ruoyi.project.gxgw_modules.pet.vo.PetVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.support.Convert;

import static com.ruoyi.project.gxgw_modules.common.CheckState.CHECKING;

/**
 * 宠物 服务层实现
 * 
 * @author ruoyi
 * @date 2019-01-18
 */
@Service
public class PetServiceImpl implements IPetService 
{
	@Autowired
	private PetMapper petMapper;

	/**
     * 查询宠物信息
     * 
     * @param petId 宠物ID
     * @return 宠物信息
     */
    @Override
	public Pet selectPetById(Integer petId)
	{
	    return petMapper.selectPetById(petId);
	}
	
	/**
     * 查询宠物列表
     * 
     * @param pet 宠物信息
     * @return 宠物集合
     */
	@Override
	public List<PetVO> selectPetList(PetVO pet)
	{
	    return petMapper.selectPetList(pet);
	}
	
    /**
     * 新增宠物
     * 
     * @param pet 宠物信息
     * @return 结果
     */
	@Override
	public int insertPet(Pet pet)
	{
	    return petMapper.insertPet(pet);
	}
	
	/**
     * 修改宠物
     * 
     * @param pet 宠物信息
     * @return 结果
     */
	@Override
	public int updatePet(Pet pet)
	{
		int checkState = pet.getCheckState();
		switch (CheckState.matchState(checkState)) {
			case CHECKING :
				pet.setPetState(PetAuthState.AUTH_CHECKING.getCode());
				break;
			case ACCESS :
				pet.setPetState(PetAuthState.AUTH_ACCESSED.getCode());
				break;
			case DENY :
				pet.setPetState(PetAuthState.AUTH_CHECKING.getCode());
				break;
			default :
				return 0;
		}
	    return petMapper.updatePet(pet);
	}

	/**
     * 删除宠物对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deletePetByIds(String ids)
	{
		return petMapper.deletePetByIds(Convert.toStrArray(ids));
	}
	
}
